package reduce.fz.com.reduce.fragment;

import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import reduce.fz.com.reduce.R;
import reduce.fz.com.reduce.adapter.SelfCenterAdapter;
import reduce.fz.com.reduce.init.RecycleOper;


public class SelfCenterFragment extends Fragment {
    private RecyclerView selfviewlist;
    private SelfCenterAdapter selfCenterAdapter;

    public static  SelfCenterFragment  create()
    {
        Bundle bundle=new Bundle();
        SelfCenterFragment fragment=new SelfCenterFragment();
        return fragment;
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_self_center, container, false);
        initWidget(view);
        return view;
    }

    public void initWidget(View view) {
        selfCenterAdapter = new SelfCenterAdapter(view.getContext());
        this.selfviewlist = (RecyclerView) view.findViewById(R.id.selfviewlist);
        GridLayoutManager llm = new GridLayoutManager(view.getContext(),2);
        selfviewlist.setLayoutManager(llm);
        // 设置ItemAnimator
        selfviewlist.setItemAnimator(new DefaultItemAnimator());
        // 设置固定大小
        selfviewlist.setHasFixedSize(true);
        GridLayoutManager.SpanSizeLookup spanSizeLookup = new DefaultSpanSizeLookup(selfCenterAdapter);
        llm.setSpanSizeLookup(spanSizeLookup);
        this.selfviewlist.setAdapter(selfCenterAdapter);

    }

    public static final class DefaultSpanSizeLookup extends GridLayoutManager.SpanSizeLookup {

        public SelfCenterAdapter selfCenterAdapter;

        public DefaultSpanSizeLookup(SelfCenterAdapter selfCenterAdapter) {
            this.selfCenterAdapter = selfCenterAdapter;
        }

        @Override
        public int getSpanSize(int position) {
            return selfCenterAdapter.getSpanSize(position);
        }

        @Override
        public int getSpanIndex(int position, int spanCount) {
            return selfCenterAdapter.getSpanIndex(position, spanCount);
        }
    }


}
